package com.sgcc.ln.pmos.e_ln_order.activity;

import android.text.TextUtils;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.LogUtils;
import com.github.barteksc.pdfviewer.PDFView;
import com.sgcc.ln.pmos.arouter.order.OrderArouterPath;
import com.sgcc.ln.pmos.common.base.BaseActivity;
import com.sgcc.ln.pmos.common.http.DownloadUtil;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.pmos.nativesdk.R;

import java.io.File;

/**
 * 合同详情
 */
@Route(path = OrderArouterPath.ORDER_CONTRACTDETAILS)
public class ContractDetailsActivity extends BaseActivity {

    private TitleBar titleBar;
    private PDFView pdfView;

    @Autowired
    public String hyxqFileId;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_contractdetails;
    }

    @Override
    protected void initViews() {
        super.initViews();
        titleBar = (TitleBar) findViewById(R.id.title_bar);
        pdfView = (PDFView) findViewById(R.id.pdfView);
        titleBar.setTitle("合同详情");

        if (!TextUtils.isEmpty(hyxqFileId)) {
            DownloadUtil.get().downloadPdf(mContext, hyxqFileId, new DownloadUtil.OnDownloadListener() {
                @Override
                public void onDownloadSuccess(File file) {
                    pdfView.fromFile(file)
                            .defaultPage(0)
                            .enableAnnotationRendering(true)
                            .spacing(10)
                            .load();
                }

                @Override
                public void onDownloading(int progress) {
                    LogUtils.v("正在下载" + progress);
                }

                @Override
                public void onDownloadFailed(Exception e) {
                    LogUtils.v("加载失败");
                }
            });
        }
    }
}
